package com.game.service.windows;

import com.game.service.Main;
import com.game.service.define.GameDefine;
import com.game.service.define.RoomConfig;
import com.game.service.socket.SocketServer;

import javax.swing.*;
import java.awt.event.ActionEvent;


public class Client extends JFrame {
    public StringBuffer sbuf = new StringBuffer();

    JLabel label = new JLabel("提示文本");
    JButton button = new JButton("关闭程序");
    JButton buttonAdd = new JButton("新增PK比赛");

    public Client() {
        setTitle(RoomConfig.SERVER_NAME); // 设置窗口标题
        setSize(400, 300); // 设置窗口大小（宽度 x 高度）
        setResizable(false); // 窗口大小不可更改
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // 设置窗口关闭操作，默认为隐藏或无操作

        setLocationRelativeTo(null); // 窗口居中显示

        JPanel panel = new JPanel();

        button.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                close();
            }
        });


        buttonAdd.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                addMatch();
            }
        });

        panel.add(button);
        panel.add(buttonAdd);
        panel.add(label);
        this.getContentPane().add(panel);
        setVisible(true); // 显示窗口

    }

    public void close() {
        int option = JOptionPane.showConfirmDialog(null, "你确定要退出吗？", "退出程序", JOptionPane.YES_NO_OPTION);

        if (option == JOptionPane.YES_OPTION) {
            Main.setClose();
            label.setText("管理员点击了确定,立即踢掉所有玩家,当局结算后关闭服务器程序");
        } else if (option == JOptionPane.NO_OPTION) {
            label.setText("管理员取消了操作");
        }
    }

    public void addMatch() {
        int option = JOptionPane.showConfirmDialog(null, "你确定要新增比赛吗？", "新增PK", JOptionPane.YES_NO_OPTION);

        if (option == JOptionPane.YES_OPTION) {
            SocketServer.getKernel().getLivePKMgr().addLivePKMatch();
        } else if (option == JOptionPane.NO_OPTION) {
            label.setText("管理员取消了操作");
        }
    }

}